package site.wlwsjsx.iot_backend.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class CorsConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**") // 允许所有接口
                .allowedOrigins("http://localhost:8080") // 前端运行地址
                .allowedMethods("GET", "POST") // 允许的请求方式
                .allowCredentials(true) // 允许携带 Cookie
                .maxAge(3600); // 预检请求有效期
    }
}